package br.edu.univas.si.engs.view;

import java.awt.BorderLayout;
import java.util.ArrayList;

import javax.swing.JDialog;
import javax.swing.JFrame;

import br.edu.univas.si.engs.controller.Controller;
import br.edu.univas.si.engs.model.RentTO;



public class FrameConsultarLocEntreg extends JDialog {

	private static final long serialVersionUID = 1L;
	
	
	private PanelConsultarLoc panelConsultaLoc;;
	private Controller controller;
	




	public FrameConsultarLocEntreg(String cliente, JFrame object, String string, boolean b){
		super(object,string,b);
		setTitle("Consultar Locacao");
		//setLocationRelativeTo(null); 
		initialziee(cliente);
		
		setLocation(290, 130);
		//setModal(true);
		pack();
		
	}
	

	
	private void initialziee(String cliente) {
		add(getPanelConsultaLoc(cliente ),BorderLayout.CENTER);
		
	}



	public PanelConsultarLoc getPanelConsultaLoc(String cliente) {
		if(panelConsultaLoc==null){
			panelConsultaLoc= new PanelConsultarLoc(cliente);
			panelConsultaLoc.setButtonListenerConsultaLocEntreg(new ButtonListenerConsultarLocEntreg() {
				
				@Override
				public void limparLoacaoAction() {
					panelConsultaLoc.getNomeField(null).setText(null);
			        panelConsultaLoc.limparTable();
			   
					
				}
				
				@Override
				public void consultaLoacaoAction() {
					ArrayList<RentTO> arraylocacao= new ArrayList<RentTO>();
					RentTO re = new RentTO();
					re= getPanelConsultaLoc(null).getcontactLocacao();
					
					String nome= re.getNomecliente();
					String marca=re.getModelocarro();
					String data= re.getDataSaida();
					
					
					System.out.println("NomeField"+nome);
					System.out.println("Modelo"+marca);
					System.out.println("Data"+data);
					
					arraylocacao=getController().consultaLocacao(nome);
					 panelConsultaLoc.limparTable();
					getPanelConsultaLoc(null).addContactLoacao(arraylocacao);
					
					
				}

				
			});
		}
		return panelConsultaLoc;
	}








	public Controller getController() {
		if(controller==null){
			
			controller= new Controller(null, null, null, null, null);
		}
		return controller;
	}

	

}
